<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 
 * 主函数，用来做程序，所有控制器都要经过这里
 * 
 * @author yunyun
 * 
 */
 
class MY_Controller extends CI_Controller {
	
	var $CI 				= null;
	
	/**
	 * 
	 * @var $con_path url 路径
	 * @var $model_path 模型路径
	 * @var $view_path 视图路径
	 * @var $lang_path 语言路径
	 * @var $validation_path 脚本检验
	 * 
	 */
	
	var $con_path 			= '';
	var $model_path 		= '';
	var $view_path 			= '';
	var $lang_path 			= '';
	var $validation_path	= '';
	
	
	function __construct()
	{
		parent::__construct();
		
		//初始化ci实例
		$this->CI = & get_instance();
		
		/**
		 * 加载语言
		 */
		if(trim($this->lang_path) != '')
		{
			$this->CI->lang->load($this->lang_path);
		}
		
		/**
		 * model
		 */
		if(trim($this->model_path) != null)
		{
			$this->CI->load->model($this->model_path);		
		}
		
		
		log_message('debug', "MY_Controller Class Initialized.");
	}
	
	public function limit()
	{
		$p = $this->CI->input->post_get('p', TRUE)?$this->CI->input->post_get('p', TRUE):1;
		$limit = $this->CI->input->post_get('limit', TRUE)?$this->CI->input->post_get('limit', TRUE):10;
		
		return $limit.",".$limit*($p-1);
	}
	
	public function view($type = 500, $data = NULL, $message = "")
	{
		
		$data_info['type'] = $type;
		$data_info['data'] = $data;
		$data_info['message'] = $message;
		
		
		echo json_encode($data_info);
		
		exit();
	}
	
}